function InvincibleReset takes nothing returns nothing
	local timer resetTimer = GetExpiredTimer()
	local unit caster = LoadUnitHandle(udg_HT , GetHandleId(resetTimer) , 3)
	local effect shieldEffect = LoadEffectHandle(udg_HT , GetHandleId(resetTimer) , StringHash("SPECIAL_EFFECT"))
	//--
	call ModifyUnitDefendPercent(caster , -100.0) 
	call DestroyEffect(shieldEffect)
	call PauseTimer(resetTimer)
	call FlushChildHashtable(udg_HT , GetHandleId(resetTimer))
	call DestroyTimer(resetTimer)
	//--
	set resetTimer = null
	set caster = null
endfunction

function Invincible takes nothing returns nothing
	local unit caster = GetTriggerUnit()
	local timer resetTimer = CreateTimer()
	local effect shieldEffect = AddSpecialEffectTarget("Abilities\\Spells\\Human\\DivineShield\\DivineShieldTarget.mdl" , caster , "origin")
	//--
	call SaveUnitHandle(udg_HT , GetHandleId(resetTimer) , 3 , caster)
	call TimerStart(resetTimer , 6.0 , false , function InvincibleReset)
	call SaveEffectHandle(udg_HT , GetHandleId(resetTimer) , StringHash("SPECIAL_EFFECT") , shieldEffect)
	call ModifyUnitDefendPercent(caster , 100.0)
	call UnitUsedAbilityWithDelta(caster , 'A01N' , 1.0)
	//--
	set caster = null
	set resetTimer = null
endfunction

function Trig_InvincibleTryActions takes nothing returns nothing
	if GetSpellAbilityId() == 'A01N' then
		call Invincible()
	endif
endfunction

function InitTrig_Invincible takes nothing returns nothing
	local hashtable masteryTable = InitHashtable()
	local integer abilityId = 'A01N'
	//--	
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("NEXT_ABILITY") , 'A023')
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("HOTKEY") , StringHash("Q"))
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MASTERY_ID") , StringHash("INVINCIBLE_MASTERY"))
	call SaveStr(udg_AbilityDataHashTable , abilityId , StringHash("NAME") , "無敵")
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MAX_LEVEL") , 3)
	call SaveHashtableHandle(udg_AbilityDataHashTable , abilityId , StringHash("LEVEL_MASTERY_TABLE") , masteryTable)
	call SaveReal(masteryTable , 1 , 0 , 3.0)
	call SaveReal(masteryTable , 2 , 0 , 7.0)
	call SaveReal(masteryTable , 3 , 0 , 12.0)
	
	set gg_trg_Invincible = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_Invincible , EVENT_PLAYER_UNIT_SPELL_EFFECT )
	call TriggerAddAction(gg_trg_Invincible , function Trig_InvincibleTryActions)
	//--
	set masteryTable = null
endfunction